﻿@model NCP.Recruiting.WebApp.Models.SavedSearchListViewModel
@using NCP.Recruiting.WebApp.Extensions;
@{
    ViewBag.Title = "人才搜索器";
}
<script type="text/javascript">
    $(function () {
        $('#btnDeleteSelected').bind('click', function () {
            var selectedCount = $('.itemChecked:checked').length;
            if (selectedCount == 0) {
                alert("请先选择要进行操作的搜索器！");
                return false;
            }
            if (!confirm("确定要删除所选搜索器吗？")) {
                return false;
            }
            var idList = "";
            $(".itemChecked:checked").each(function () {
                idList += $(this).val() + ",";
            });
            $('#hidIdList').val(idList)
        });

        $('#dialog').dialog({
            autoOpen: false,
            resizable: false,
            height: 250,
            width: 400,
            modal: true,
            buttons: {
                "立即订阅": function () {
                    if ($.trim($('#txtEmail').val()) == '') {
                        alert('请输入接收邮件地址！');
                        return;
                    }
                    $('#btnSubscribe').click();
                },
                "取消": function () {
                    $(this).dialog("close");
                }
            }
        });

        $('.chkAll').bind('click', function () {
            $('.itemChecked').prop('checked', $(this).prop('checked'));
        });
    });

    function unsubscribe(id) {
        if (!confirm("确定要退订吗？")) {
            return false;
        }
        $('#hidUnsubscribeId').val(id);
        $('#btnUnsubscribe').click();
    }

    function subscribe(id, email) {
        $('#hidSubscribeId').val(id);
        $('#txtEmail').val(email);
        $('#dialog').dialog('open');
    }

</script>
<div id="wrap">
    <div class="wrapContents">
        <h1>
            人才搜索器
        </h1>
        <div class="search">
            <div class="search_left">
                <div class="caozuo">
                    @Html.ActionLink("新建搜索器", "AddSearcher")
                </div>
                <div class="gjss">
                    <a href="#" onclick="$('#btnDeleteSelected').click()">删除搜索器</a>
                    @using (Html.BeginForm())
                    {
                        <input type="submit" id="btnDeleteSelected" value="删除所选" name="DeleteSelected" style="display: none" />
                        <input type="hidden" id="hidIdList" name="idList" />
                    }
                </div>
                <div class="cl">
                </div>
            </div>
            <div class="search_right">
                @Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber")
            </div>
            <div class="cr">
            </div>
        </div>
        <table cellpadding="0" cellspacing="0" width="100%" id="tblJobList">
            <thead>
                <tr>
                    <th>
                        <input class="chkAll" type="checkbox" />
                    </th>
                    <th>
                        &nbsp;
                    </th>
                    <th>
                        搜索器名称
                    </th>
                    <th>
                        上次使用
                    </th>
                    <th>
                        订阅
                    </th>
                    <th>
                        周期
                    </th>
                    <th>
                        发送简历份数
                    </th>
                    <th>
                        邮件地址
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
            </thead>
            <tbody id="tbodyJobList">
                @foreach (var item in Model.SavedSearchList)
                {
                    <tr>
                        <td>
                            <input type="checkbox" class="itemChecked" value="@item.Id">
                        </td>
                        <td>
                            &nbsp;
                        </td>
                        <td style="text-align: left">
                            @Html.ActionLink(item.SearchName, "List", new { searchId = item.Id })
                        </td>
                        <td>
                            @item.LastSearched
                        </td>
                        <td>
                            @if (item.IsSubscribed)
                            {
                                <img src="/Content/images/subscribed.jpg"/>
                            }
                        </td>
                        <td>
                            @item.Frequency
                        </td>
                        <td>
                            @item.Talents
                        </td>
                        <td>
                            @item.Email
                        </td>
                        <td>
                            @Html.ActionLink("编辑", "EditSearcher", new { id = item.Id }) |
                            @if (@item.IsSubscribed)
                            {
                                <a href="#" onclick="unsubscribe('@item.Id')">退订</a>
                            }
                            else
                            {
                                <a href="#" onclick="subscribe('@item.Id','@item.Email') ">订阅</a>
                            }
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        <div class="pagelists">
            <div class="search_right">
                @Html.Pager(Model.PagingFilteringContext).QueryParam("pagenumber")
            </div>
            <div class="cr">
            </div>
        </div>
    </div>
</div>
@using (Html.BeginForm())
{
    <input type="submit" id="btnUnsubscribe" value="退订" name="Unsubscribe" style="display: none" />
    <input type="hidden" id="hidUnsubscribeId" name="unsubscribeId" />
}
<div id="dialog" title="订阅选项" class="condition_box">
    @using (Html.BeginForm())
    {
        <p>
            <label>
                发送周期
            </label>
            @Html.DropDownListFor(x => x.ResumeSubscribe.Frequency, Model.ResumeSubscribe.FrequencyList, new { style = "width:100px" })
        </p>
        <p>
            <label>
                发送简历数
            </label>
            @Html.DropDownListFor(x => x.ResumeSubscribe.Talents, Model.ResumeSubscribe.TalentsList, new { style = "width:100px" })
        </p>
        <p>
            <label>
                接受邮件
            </label>
            @Html.TextBoxFor(x => x.ResumeSubscribe.Email, new { id = "txtEmail", style = "width:200px" })
        </p>
        @Html.HiddenFor(x => x.ResumeSubscribe.Id, new { id = "hidSubscribeId" })
        <input type="submit" id="btnSubscribe" value="订阅" name="Subscribe" style="display: none" />
    }
</div>
